package com.qf.sys.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.sys.po.Citys;
import com.qf.sys.po.Provincial;
import com.qf.sys.service.CitysService;
import com.qf.sys.service.ProvincialService;
import com.qf.sys.util.Msg;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @创建人 sunsir Email:sunsir163@163.com
 * @创建时间 2022/5/8
 * @描述
 */
@Controller
@RequestMapping("area")
public class AreaController {
    @Resource
    CitysService citysService;
    @Resource
    ProvincialService provincialService;

    @RequestMapping("getAreaList")
    @ResponseBody
    public Msg getAreaList(HttpServletRequest request){
        int pageSize =Integer.parseInt(request.getParameter("limit"));
        int pageNumber = Integer.parseInt(request.getParameter("page"));
        String _pno = request.getParameter("id");
        int pno = 0;
        if (_pno != null && !"".equals(_pno)) {
            pno = Integer.parseInt(_pno);
        }
        String provincial = request.getParameter("provincial");
        String city = request.getParameter("city");


        Map params = new HashMap();
        params.put("city", city);
        params.put("pno", pno);
        params.put("provincial", provincial);
        PageHelper.startPage(pageNumber, pageSize);
        PageInfo<Citys> data = citysService.getCityList(params);
        Msg msg = new Msg();
        msg.setCode(0);
        msg.setMsg("处理成功");
        msg.setCount(data.getTotal());//得到总条数
        msg.setData(data.getList());//得到查出的List数据
        System.out.println(msg);
        return msg;
    }
    @RequestMapping("getProvincialList")
    @ResponseBody
    public Msg getProvincialList(HttpServletRequest request){
        String _pno = request.getParameter("id");
        int pno = 0;
        if (_pno != null && !"".equals(_pno)) {
            pno = Integer.parseInt(_pno);
        }
        Map params = new HashMap();
        params.put("pno", pno);
        PageInfo<Provincial> data= provincialService.getProvincialList(params);
        Msg msg = new Msg();
        msg.setCode(0);
        msg.setMsg("处理成功");
        msg.setCount(data.getTotal());//得到总条数
        msg.setData(data.getList());//得到查出的List数据
        System.out.println(msg);
        return msg;

    }
    @RequestMapping("getCitylList")
    @ResponseBody
    public Msg getCitylList(HttpServletRequest request){
        String _pno = request.getParameter("id");
        int pno = 0;
        if (_pno != null && !"".equals(_pno)) {
            pno = Integer.parseInt(_pno);
        }
        Map params = new HashMap();
        params.put("pno", pno);
        PageInfo<Citys> data= citysService.getCityList(params);
        Msg msg = new Msg();
        msg.setCode(0);
        msg.setMsg("处理成功");
        msg.setCount(data.getTotal());//得到总条数
        msg.setData(data.getList());//得到查出的List数据
        System.out.println(msg);
        return msg;

    }

}
